//
//  MSRequest.h
//  OrderingMerchantsSide
//
//  Created by iOS on 2018/10/8.
//  Copyright © 2018年 mls. All rights reserved.
//

#import <Foundation/Foundation.h>

/** 网络活动指示器开始 */
#define ms_startSystemLoading  [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]
/** 网络活动指示器结束 */
#define ms_endSystemLoading    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]


NS_ASSUME_NONNULL_BEGIN

/** 网络请求 */
@interface MSRequest : NSObject

@property (nonatomic, strong)   AFHTTPSessionManager  *sessionManager;  ///< [AFNetWorking]的operationManager对象
@property (nonatomic, strong)   NSOperationQueue      *operationQueue;    ///< 当前的请求operation队列

/**
 *功能: 创建CMRequest的对象方法
 */
+ (instancetype)request;

/** get 请求 response content type = “image/png” */
- (void)ms_getImageDataWithURLStr1:(nonnull NSString *)URLStr
                          response:(nonnull void(^)(NSData * _Nullable data, NSString * _Nonnull msg))response;
/** get 请求 */
- (void)ms_getWithURLStr1:(nonnull NSString *)URLStr
               parameters:(nullable NSDictionary *)parameters
                 response:(nonnull void(^)(NSString * _Nonnull code, NSString * _Nullable dataJSON, NSString * _Nonnull msg))response;
/** post 请求(可传请求头部信息) */
- (void)ms_postWithURLStr1:(nonnull NSString *)URLStr
                parameters:(nullable NSDictionary *)parameters
                   headers:(nullable NSDictionary *)headers
                  response:(nonnull void(^)(NSString * _Nonnull code, NSString * _Nullable dataJSON, NSString * _Nonnull msg))response;
/** post 请求 */
- (void)ms_postWithURLStr1:(nonnull NSString *)URLStr
                parameters:(nullable NSDictionary *)parameters
                  response:(nonnull void(^)(NSString * _Nonnull code, NSString * _Nullable dataJSON, NSString * _Nonnull msg))response;


#pragma mark - RACSignal
/** get 请求image，return RACSignal */
- (RACSignal *)ms_getImageDataWithURLStr:(nonnull NSString *)URLStr;
/** get 请求(可传请求头部信息) ，return RACSignal  */
- (RACSignal *)ms_getWithURLStr:(nonnull NSString *)URLStr
                     parameters:(nullable NSDictionary *)parameters
                        headers:(nullable NSDictionary *)headers;
/** get 请求，return RACSignal */
- (RACSignal *)ms_getWithURLStr:(nonnull NSString *)URLStr
                     parameters:(nullable NSDictionary *)parameters;


/** post 请求(可传请求头部信息)，return RACSignal */
- (RACSignal *)ms_postWithURLStr:(nonnull NSString *)URLStr
                      parameters:(nullable NSDictionary *)parameters
                         headers:(nullable NSDictionary *)headers;
/** post 请求，return RACSignal*/
- (RACSignal *)ms_postWithURLStr:(NSString *)URLStr
                      parameters:(NSDictionary *)parameters;


#pragma mark - 上传文件
/** 上传文件 */
- (RACSignal *)ms_uploadFile:(NSData *)file
                        name:(NSString *)name
                    fileName:(NSString *)fileName
                      URLStr:(nonnull NSString *)URLString
                  parameters:(nullable NSDictionary *)parameters
                     headers:(nullable NSDictionary *)headers;

@end

NS_ASSUME_NONNULL_END
